/* Papastefanos Serafeim */
/* Sunarthseis gia mh-asfalh epikoinwnia */

#ifndef _LOW_H
#define _LOW_H

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#ifdef _CWMP_WIN
////// Windows version includes //////
#include <windows.h>
#include <winsock.h>
//#include <conio.h>
#else
////// Unix version include //////
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

#include <unistd.h>
#include <signal.h>

#endif


#include "helpers.h"
#include "client.h"

#ifndef _CWMP_WIN // To UNIX den exei defined ton tupo SOCKET
#define SOCKET unsigned int 
#endif

#define MAXBUF 256 /* H sta9era MAXBUF exei to megisto ari9mo xarakthrwn
pou epitrepetai na periexei mia grammh sthn epikefalida tou HTTP mhnumatos.
Mporoume na ths dwsoume opoia timh 9eloume. */

/* Stellei ta StringList ws HTTP mhnuma - ka9e StringList einai kai ena
oloklhro soap message */
void sendRawMessage(SOCKET sd, StringList *);

/* Diavazei ena mhnuma pou elave - isws uparxoun perissotera apo ena mhnumata */
char *getRawMessage(SOCKET sd);

/* Xwrizei ena mhnuma pou isws periexei perissotera apo ena soap envelopes
se epimerous mhnumata */
StringList *splitRawMessage(char *rawMessage);

/* Briskei ton ari9mo twn epimerous soap mhnumatwn apo ta opoia apoteleitai
ena lhf9en mhnuma */
unsigned int getNumOfMessages(char *rawMessage);

/* Xrhsimopoiei tis treis parapanw sunarthseis gia na epistrefei ap'eu9eias ta 
mhnumata pou esteile o server */
StringList *getMessages(SOCKET sd);

/* Diavazei mia grammh - xrhsimopoieitai gia tis epikefalides tou http */
char *getLine(SOCKET sd);

/* Epistrefei ena string list me thn epikefalida - xreiazetai to mhkos tou mhnumatos */
StringList *createHeaders(unsigned int msglen);

/* Aparaithto gia to winsock */
void initWinsock(void); 

/* Sundesh sth d/sh kai th 9ura pou perniountai ws parametroi. Xrhsimo gia th
   leitourgia tou client */
SOCKET makeConnection(char *address, int port);

/* Dhmiourgia listening socket sth 9ura port, gia leitourgia server */
SOCKET createListeningSocket(int port);

/* Anamonh sto listening socket gia incoming connections, gia server */
SOCKET acceptConnection(SOCKET listening);

/* Elegxei an o ACS esteile to katallhlo mhnuma ston client, epistrefei 1 an ok, 0 an oxi */
int checkConnectionString(char *, SOCKET);



#endif //_LOW_H
